//
// Created by xili on 2024/9/10 11:25.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    long long maximumHappinessSum(vector<int> &happiness, int k) {
        priority_queue<int> pq(happiness.begin(), happiness.end());
        long long ans = 0;
        int select = 0;
        while (k-- > 0) {
            if (pq.top() - select <= 0) {
                break;
            }
            ans += pq.top() - select;
            select++;
            pq.pop();
        }
        return ans;
    }
};